package cn.yunhe.control;

import cn.yunhe.entity.Topic;
import cn.yunhe.server.TopicServer;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/DeletTopicServlet")
public class DeletTopicServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int pId = Integer.parseInt(request.getParameter("pId"));
        Topic topic = new Topic();  //新建主贴对象
        topic.setpId(pId);
        //新建server对象
        TopicServer topicServer = new TopicServer();
        boolean flag = topicServer.TopicDelete(topic);
        if (flag){
            request.setAttribute("result","帖子删除成功!!");
            request.getRequestDispatcher("managerAllTopic.jsp").forward(request,response);
        }else {
            request.setAttribute("result","帖子删除失败!!");
            request.getRequestDispatcher("managerAllTopic.jsp").forward(request,response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
